<?php





namespace app\admin\controller;





use app\admin\model\SysModel;

use app\BaseController;

use app\common\Constants\ErrorCode;

use think\Model;

use think\response\Json;



class Sys extends ApiCommon

{



    /**

     * 用于判断权限

     * @permission 无限制

     * @allow 登录用户可访问

     * @author Mr.Li

     * @create 2021-05-26 16:20

     */

    public function initialize()

    {

        parent::initialize();

    }



    /**

     * 获取系统首页信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function readAdminSysHomeInfo():Json

    {

        $request = $this->request->param();

        $model = new SysModel();

        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];
        $request['shop_person_id'] = $this->userInfo['shop_person_id'];

        if(!empty($request['shopId'])){

            $shopIds =[$request['shopId']];

        }
        $res          = $model->getAdminSysHomeInfoResource($shopIds,$request);

        return $this->success($res,'获取资源成功');

    }

    /**

     * 获取系统首页员工业绩

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function readAdminSysHomePersonAchieve():Json

    {

        $request = $this->request->param();

        $model = new SysModel();

        $shopIds =$this->getCommonShopIdsCollectByUserType();

        if(empty($shopIds)){

            $shopIds =[-1];

        }

        if(!empty($request['shopId'])){

            $shopIds =[$request['shopId']];

        }

        $request['user_id'] = $this->userInfo['id'];

        $request['shop_person_id'] = $this->userInfo['shop_person_id'];

        $res          = $model->getAdminSysHomePersonAchieveResource($shopIds,$request);

        return $this->success($res,'获取资源成功');

    }

    /**

     * 获取系统首页信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function readAdminSysServerInfo():Json

    {

        $model = new SysModel();

        $res          = $model->getAdminSysServerInfoResource();

        return $this->success($res,'获取资源成功');

    }

    /**

     * 获取系统登录日志

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function readAdminSysLoginLog():Json

    {

        $model = new SysModel();

        $res          = $model->getAdminSysLoginLogResource();

        return $this->success($res,'获取资源成功');

    }

    /**

     * 获取系统账户信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function readAdminSysUser():Json

    {

        $model = new SysModel();

        $userId =$this->userInfo['id']??1;

        $res          = $model->getAdminSysUserResource($userId);

        return $this->success($res,'获取资源成功');

    }

    /**

     * 获取系统账户信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function getAdminSysUserInfo():Json

    {

        $model = new SysModel();

        $userId =$this->userInfo['id']??1;

        $res          = $model->getAdminSysUserInfoResource($userId);

        return $this->success($res,'获取成功');

    }

    /**

     * 更新系统账户信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function updateAdminSysUser():Json

    {

        $request = $this->request->param();

        $model = new SysModel();

        $userId =$this->userInfo['id']??1;

        $res          = $model->updateAdminSysUserResource($request,$userId);

        if (!$res) {

            return  $this->failed(ErrorCode::SYSTEM_INVALID,$model->getError());

        }

        return  $this->success([],'更新成功');

    }

    /**

     * 获取小程序首页信息

     * @return Json

     * @author ran

     * @date 2021-09-22 17:09

     * mailbox 466180170@qq.com

     */

    public function miniApi():Json

    {

        $request = $this->request->param();

        $model = new SysModel();

        $shopIds =$this->getCommonShopIdsCollectByUserType();
        $request['user_id'] = $this->userInfo['id'];

        return resultArray(['error' => '获取成功', 'data' => $request??'']);

    }

}
